/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import aexcasus.willem.elton.BannerController;
import aexcasus.willem.elton.MockEffectenbeurs;
import interfaces.IFonds;
import java.rmi.RemoteException;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author willem
 */
public class AexBanner extends javax.swing.JFrame {
    
    BannerController bC;
    java.util.Timer refreshTimer;
    private static final int REFRESH = 24;
    MockEffectenbeurs eB;
    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            StringBuilder sB = new StringBuilder();
        for(IFonds f: eB.getKoersen()) {
                try {
                    sB.append(f.getNaam()).append(": ").append(f.getKoers()).append(" | ");
                } catch (RemoteException ex) {
                    Logger.getLogger(AexBanner.class.getName()).log(Level.SEVERE, null, ex);
                }
        }
        setKoersen(sB.toString());
        }
        
    };

    /**
     * Creates new form AexBanner
     */
    public AexBanner() {
        initComponents();
        //Creer wat koersen.
        eB = new MockEffectenbeurs();
        bC = new BannerController(eB, this);
        refreshTimer = new java.util.Timer();
        refreshTimer.schedule(task, REFRESH, REFRESH);
        
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        aexPanel1 = new gui.AexPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout aexPanel1Layout = new javax.swing.GroupLayout(aexPanel1);
        aexPanel1.setLayout(aexPanel1Layout);
        aexPanel1Layout.setHorizontalGroup(
            aexPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 376, Short.MAX_VALUE)
        );
        aexPanel1Layout.setVerticalGroup(
            aexPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 88, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(aexPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(aexPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AexBanner.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AexBanner.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AexBanner.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AexBanner.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AexBanner().setVisible(true);
                
            }
        });
    }
    
    public final void setKoersen(String koersen) {
        aexPanel1.setPString(koersen);
        aexPanel1.repaint();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private gui.AexPanel aexPanel1;
    // End of variables declaration//GEN-END:variables
}
